package com.rimi.service.impl;

import com.rimi.bean.News;
import com.rimi.commons.CommonResult;
import com.rimi.commons.ResultStatus;
import com.rimi.mapper.NewsMapper;
import com.rimi.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liHaiYang
 * @version V1.0
 * @Description: (用一句话描述该文件做什么)
 * @date 2021/7/9 15:15
 */
@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    NewsMapper newsMapper;

    /**
     * 用户添加新闻收藏
     * @param newsId
     * @param userId
     * @return
     */
    @Override
    public int addNewsByUserId(Integer newsId, Integer userId) {
        return newsMapper.addNewsByUserId(newsId,userId);
    }

    @Override
    public CommonResult deleteNewsByNewsId(Integer newsId) {
        int row = newsMapper.deleteNewsByNewsId(newsId);
        return row > 0? CommonResult.onSuccess(null):CommonResult.onFailed(ResultStatus.DELETE_FAILED);
    }

    @Override
    public List<News> showNewsByUserId(Integer userId) {
        return newsMapper.showNewsByUserId(userId);

    }


}
